/*
 * Copyright 2012 Dirk Vranckaert
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

package eu.vranckaert.utility.activity.test;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import eu.vranckaert.utility.activity.DirectoryPickerActivity;
import eu.vranckaert.utility.activity.abcompat.activity.ActionBarActivity;

import java.io.File;

public class LightThemedActivity extends ActionBarActivity {
    private static final int ATIVITY_REQ_CODE_FILE_SELECT = 1;
    private static final int ATIVITY_REQ_CODE_DIR_SELECT = 2;

    private File selectedFile = null;
    private File selectedDir = null;

    /**
     * Called when the activity is first created.
     */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button darkThemedActivityBtn = (Button) findViewById(R.id.dark_themed_activity);
        darkThemedActivityBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(LightThemedActivity.this, DarkThemedActivity.class);
                startActivity(intent);
            }
        });

        Button fileChooserButton = (Button) findViewById(R.id.file_chooser_file);
        fileChooserButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(LightThemedActivity.this, DirectoryPickerActivity.class);
                intent.putExtra(DirectoryPickerActivity.ONLY_DIRS, false);
                intent.putExtra(DirectoryPickerActivity.START_DIR, selectedFile);
                startActivityForResult(intent, ATIVITY_REQ_CODE_FILE_SELECT);
            }
        });
        Button dirChooserButton = (Button) findViewById(R.id.file_chooser_dir);
        dirChooserButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(LightThemedActivity.this, DirectoryPickerActivity.class);
                intent.putExtra(DirectoryPickerActivity.ALLOW_CREATE_DIR, true);
                intent.putExtra(DirectoryPickerActivity.START_DIR, selectedDir);
                startActivityForResult(intent, ATIVITY_REQ_CODE_DIR_SELECT);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (requestCode) {
            case ATIVITY_REQ_CODE_FILE_SELECT:
                if (resultCode == Activity.RESULT_OK) {
                    selectedFile = (File) data.getExtras().get(DirectoryPickerActivity.CHOSEN_FILE);
                }
                break;
            case ATIVITY_REQ_CODE_DIR_SELECT:
                if (resultCode == Activity.RESULT_OK) {
                    selectedDir = (File) data.getExtras().get(DirectoryPickerActivity.CHOSEN_FILE);
                }
                break;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        boolean r = super.onCreateOptionsMenu(menu);

        // Disable click on home-button
        setDisplayHomeAsUpEnabled(false);
        setHomeButtonEnabled(false);
        return r;
    }
}
